import { observable, action } from "mobx";
import resource from "@/utils/resource";
import API from "@/utils/monitorwarning";
class SideRightStore {
    @observable type = "APP"; // 这个type代表当前页面属于app ，人员，专题，传参时可能用到
    @observable addAppStatus = false;
    @observable addControl = false;
    @observable curItem = {};
    // @observable curOpenItem = {};

    @observable filterData = {};
    @observable listData = [];
    @observable page = {
        pageSize: 10,
        current: 1,
        total: 0
    };

    // 鼠标滑过的卡片
    @observable overCards = "";
    @observable selectedCards = [];
    @observable showBtn = false;

    @observable status = {};
    @observable curCard = {};

    @action.bound
    init = type => {
        console.log("init data");
        this.type = type || this.type;
        this.page = {
            pageSize: 10,
            current: 1,
            total: 0
        };
        this.filterData = {};
        this.showBtn = false;
        // this.getAppResultList();
        this.getRightCardResultList();
    };

    // @action.bound
    // getAppResultList() {
    //     const url = this.type === "APP" ? API.monitorwarningAPP : API.monitorwarningPeople;
    //     // this.resultData = [];
    //     resource.get(url, { type: this.curTab }).then(res => {
    //         this.resultData = res.list;
    //     });
    // }

    @action.bound
    getRightCardResultList = () => {
        console.log("this.filterData", this.filterData, "this.type", this.type);
        const url = this.type === "APP" ? API.monitorwarningAPPCardList : API.monitorwarningPeopleCardList;
        resource.get(url, { type: this.curTab, ...this.page }).then(res => {
            this.listData = res.list;
            this.page = {
                ...this.page,
                total: res.count
            };
        });
    };

    @action.bound
    changeTab = item => {
        this.curTab = item;
        // this.init();
        this.getAppResultList();
    };

    @action.bound
    selectCurItem = item => {
        this.curItem = item;
        // 左侧选中app，更新右侧卡片数据
        // this.getRightCardResultList();
    };

    // @action.bound
    // selectCurOpenItem = item => {
    //     this.curOpenItem = item;
    // };

    // @action.bound
    // changeCurOpenItem = item => {
    //     this.curOpenItem = {
    //         ...this.curOpenItem,
    //         ...item
    //     };
    // };

    @action.bound
    delete = item => {
        console.log("delete one item", item);
        this.getAppResultList();
    };

    @action.bound
    addControl = () => {
        console.log("加入管控,刷新数据");
        this.getAppResultList();
    };

    @action.bound
    changePage = pageinfo => {
        this.page = { ...this.page, ...pageinfo };
        this.getRightCardResultList();
    };

    @action.bound
    setFilterData = item => {
        this.filterData = {
            ...this.filterData,
            ...item
        };
    };

    @action.bound
    mouseOverCard = (id, flag) => {
        if (flag) {
            this.overCards = "";
        } else {
            this.overCards = id;
        }
    };

    @action.bound
    activeCards = (id, checked) => {
        this.listData = [
            ...this.listData.map(item => {
                if (item.id === id) {
                    item.active = checked;
                }
                return item;
            })
        ];
        this.showBtn = this.listData.filter(item => item.active).length > 0;
    };

    @action.bound
    selectCard = item => {
        this.curCard = item;
    };

    @action.bound
    updateStatus = newStatus => {
        this.status = {
            ...this.status,
            ...newStatus
        };
    };
}

export default new SideRightStore();
